#include "database.h"
#include"QMessageBox"
#include<QSqlQuery>

QSqlDatabase* DataBase::database=nullptr;

QSqlDatabase* DataBase::getInstance()
{
    if(database==nullptr)
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
        db.setHostName("120.24.60.17");
        db.setPort(3306);
        db.setDatabaseName("canteen");
        db.setUserName("root");
        db.setPassword("1234");
        bool ok = db.open();
        if (ok){
//            QMessageBox::information(nullptr, "infor", "success");
        }
        else {
            QMessageBox::information(nullptr, "infor", "open failed");
            //qDebug()<<"error open database because"<<db.lastError().text();
        }
        database=new QSqlDatabase(db);
    }
    return database;
}

//QSqlQuery DataBase::getQuery()
//{
//    return QSqlQuery(*getInstance());
//}
